/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-11-12
 * Time: 22:56
 */
import java.util.*;

class Student1 implements Comparable<Student> {
    public double t; // 总得分
    public double z; // 智育分
    public String s; // 名字

    public Student1(double t, double z, String s) {
        this.t = t;
        this.z = z;
        this.s = s;
    }

    public int compareTo(Student o) {
        // 先比较智育分 z，降序排列
        if (this.z != o.z) {
            return Double.compare(o.z, this.z); // z大的在前
        }
        // 再比较总得分 t，降序排列
        return Double.compare(o.t, this.t); // t大的在前
    }

    public String toString() {
        return this.s;
    }
}

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Student1[] students = new Student1[n];

        // 确保在读取浮点数后再读取名字
        in.nextLine(); // 消耗掉换行符
        for (int i = 0; i < n; i++) {
            double t = in.nextDouble();
            double z = in.nextDouble();
            String s = in.nextLine().trim(); // 读取名字，去掉前后的空白
            students[i] = new Student1(t, z, s);
        }

        Arrays.sort(students);

        // 以空格连接学生名字输出
        String result = String.join(" ", Arrays.stream(students)
                .map(Student1::toString)
                .toArray(String[]::new));
        System.out.println(result);
    }
}
